home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_351 / pdc / libsrc.lzh / LibSrc / SysIO / access.c < prev    next >
C/C++ Source or Header  |  1990-04-07  |  2KB  |  65 lines

  1. /*
  2.  * Libraries and headers for PDC release 3.3 (C) 1989 Lionel Hummel.
  3.  * PDC Software Distribution (C) 1989 Lionel Hummel and Paul Petersen.
  4.  * PDC I/O Library (C) 1987 by J.A. Lydiatt.
  5.  *
  6.  * This code is freely redistributable upon the conditions that this 
  7.  * notice remains intact and that modified versions of this file not
  8.  * be included as part of the PDC Software Distribution without the
  9.  * express consent of the copyright holders.  No warrantee of any
  10.  * kind is provided with this code.  For further information, contact:
  11.  *
  12.  *  PDC Software Distribution    Internet:                     BIX:
  13.  *  P.O. Box 4006             or hummel@cs.uiuc.edu            lhummel
  14.  *  Urbana, IL  61801-8801       petersen@uicsrd.csrd.uiuc.edu
  15.  */
  16.  
  17. /* access.c -
  18.  *     access(char *name, int mode)     - test accessability of a file/dir
  19.  */
  20.  
  21. #include <errno.h>
  22. #include <exec/types.h>
  23. #include <functions.h>
  24. #include <libraries/dosextens.h>
  25.  
  26. #define MAX_MODES 5
  27. static int mask_table[MAX_MODES] = {
  28.     0L,
  29.     FIBF_EXECUTE,
  30.     FIBF_WRITE,
  31.     -1L,
  32.     FIBF_READ
  33.     };
  34.  
  35. int access(filename, mode)
  36. char *filename;
  37. int mode;
  38. {
  39.     struct FileLock *fl;
  40.     struct FileInfoBlock fib;
  41.     int retval;
  42.  
  43.     if (mode > MAX_MODES)  {
  44.         errno = EINVAL;
  45.         return(0);
  46.         }
  47.  
  48.     fl = Lock(filename, ACCESS_READ);
  49.     if (fl == 0)  {
  50.         errno = ENOENT;
  51.         return(0);
  52.         }
  53.  
  54.     if (Examine(fl, &fib) == DOSFALSE)  {
  55.         errno = EIO;
  56.         retval = 0;
  57.         }
  58.     else  {
  59.         retval = !(fib.fib_Protection & mask_table[mode]);
  60.         }
  61.  
  62.     UnLock(fl);
  63.     return(retval);
  64. }
  65.